home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8194 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Something about typedef and functions I don't understand
  5. Date: 1 Mar 1996 15:22:35 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4h80rrINNpoj@anvil.ugrad.cs.ubc.ca>
  8. References: <4h6924$ihl@pith.uoregon.edu>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4h6924$ihl@pith.uoregon.edu>,
  12. Pat O'Connor  <pwoc@darkwing.uoregon.edu> wrote:
  13.  >I just ran into a problem using typedef for declaring aliases for function
  14.  >types.  Now, I thought that when I say for example,
  15.  >    typedef double (*DFunc)(double x);
  16.  >that I could use DFunc to declare (but not define) functions. But.... when
  17.  >I try to compile the following program, the linker has a fit. (granted,
  18.  >the program is pretty stupid - I just wanted to simplify things as much as 
  19.  >possible).
  20.  >
  21.  >in file 1                in file 2
  22.  >--------------------------              --------------------------
  23.  >#include <stdio.h>            double f(double x) { return x*x;}
  24.                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  25.                                          this is a function
  26.  
  27.  >typedef double (*DFunc)(double x);
  28.  >double DoFunction(DFunc f, double x)
  29.  >{    return f(x);  }
  30.  >
  31.  >extern DFunc f;
  32.   ^^^^^^^^^^^^^^^ 
  33.   this is a pointer to a function, not a function prototype
  34. -- 
  35.  
  36.